<?php

namespace App\Http\Controllers\Home;

use App\Model\M9_cate;
use App\Model\M9_good;
use App\Models\User;
use App\Models\Reply;
use App\Models\Comment;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class GoodController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request,$gid)
    {
        //
        $data = M9_good::where('gid',$gid)->get();


        // dd($gcstatus);
        $comment0 = Comment::where('gc_gid',$gid)->orderBy('gctime','desc')->get();
        $comment1 = Comment::where('gc_gid',$gid)->where('gcstatus','好评')->orderBy('gctime','desc')->get();
        $comment2 = Comment::where('gc_gid',$gid)->where('gcstatus','中评')->orderBy('gctime','desc')->get();
        $comment3 = Comment::where('gc_gid',$gid)->where('gcstatus','差评')->orderBy('gctime','desc')->get();
        foreach($comment0 as $k=>$v){
           $comment0[$k]['user'] = User::find($v['gc_uid']);
           $comment0[$k]['reply'] = Reply::where('r_gcid',$v['gcid'])->first();
            // dd($a);
        }
        foreach($comment1 as $k=>$v){
            $comment1[$k]['user'] = User::find($v['gc_uid']);
            $comment1[$k]['reply'] = Reply::where('r_gcid',$v['gcid'])->first();
        }
        foreach($comment2 as $k=>$v){
            $comment2[$k]['user'] = User::find($v['gc_uid']);
            $comment2[$k]['reply'] = Reply::where('r_gcid',$v['gcid'])->first();
        }
        foreach($comment3 as $k=>$v){
            $comment3[$k]['user'] = User::find($v['gc_uid']);
            $comment3[$k]['reply'] = Reply::where('r_gcid',$v['gcid'])->first();
            // dd($a);
        }


        $comment = [$comment0,$comment1,$comment2,$comment3];
        // dd($comment);
        return view('home/good',['data'=>$data,'comment'=>$comment]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
